from utils.base_response import BaseResponse


class SaveSqlDetail:
    def __init__(self, serializers, queryset, querydict):
        self.serializer = serializers
        self.queryset = queryset
        self.querydict = querydict
        self.res = BaseResponse()

    def save(self):
        serializer = self.serializer(self.queryset, data=self.querydict, partial=True)
        if serializer.is_valid():
            serializer.save()
            self.res.data = serializer.data
            self.res.msg = '测试成功，数据成功写入。'
        else:
            self.res.msg = '数据异常，本次更新失败！！！'
            self.res.error = serializer.errors
            self.res.status = 1
